﻿using Book_WebAPI.Data;
using Book_WebAPI.Models;

namespace Book_WebAPI.Services
{
    public class BookMockRepository : IBookRepository
    {
        public void AddBook(Book book)
        {
            BookMockData.BookForAuthor.Books.Add(book);
        }

        public void DeleteBook(Book book)
        {
            BookMockData.BookForAuthor.Books.Remove(book);
        }

        public IEnumerable<Book> GetBookForAuthor(int authorId)
        {
            return BookMockData.BookForAuthor.Books.Where(book => book.authorId == authorId).ToList();
        }

        public Book GetBookForAuthor(int id, int authorId)
        {
            return BookMockData.
                BookForAuthor.
                Books.
                FirstOrDefault(book => book.authorId == authorId && book.id == id);
        }

        public void UpdateBook(int authorId, int id, BookUpdate bookUpdate)
        {
            var updateBook = GetBookForAuthor(id, authorId);

            updateBook.title = bookUpdate.title;
            updateBook.description = bookUpdate.description;
            updateBook.pages = bookUpdate.pages;
        }
    }
}
